#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# author    : Xiangwei Wang
# email     : wangxw-cn@qq.com
# datetime  : 2021/5/20 16:10

"""
将随机森林对转评赞的结果进行合并
"""

import json

if __name__ == "__main__":
    result_0_file = "../../Data/predict/result_0.txt"
    result_1_file = "../../Data/predict/result_1.txt"
    result_2_file = "../../Data/predict/result_2.txt"
    data_file = "../../Data/predict/feature_sum.json"
    result_sum_file = "../../Data/predict/result_sum.txt"

    print("读取结果")
    forwards = ""
    with open(result_0_file, "r", encoding='utf-8') as f:
        forwards = f.read().split("\t")
    comments = ""
    with open(result_1_file, "r", encoding='utf-8') as f:
        comments = f.read().split("\t")
    likes = ""
    with open(result_2_file, "r", encoding='utf-8') as f:
        likes = f.read().split("\t")

    print("聚合结果")
    with open(result_sum_file, "w", encoding='utf-8') as f_w:
        with open(data_file, "r", encoding='utf-8') as f:
            users = json.load(f)
            cnt = 0
            for uid in users:
                thisUser = users[uid]
                for mid in thisUser["blogs"]:
                    res_str = f"{uid}\t{mid}\t{forwards[cnt]},{comments[cnt]},{likes[cnt]}\n"
                    f_w.write(res_str)
                    cnt += 1
    print("完成")



